<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\lib\QiUpload;
use think\facade\Db;
use think\Request;
use think\Response;

class MemberController extends ApiBase
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //解析token 获取uid 和 userinfo
        $parse = $this->Auth->parseToken();

        dump($parse);

    }

    /**
     * 登录测试
     *
     * @return Response
     */
    public function login(): Response
    {
        // 逻辑自行修改
        $userInfo = (object)Db::name('user')->where('user_name', 'admin')->find();

        // 这里就可以获取到token 传给前端 放到header头
        $userInfo->token = $this->Auth->setUid($userInfo->id)->setUserInfo($userInfo)->createToken()->getToken();

        if ($userInfo) {
            $this->result((array)[$userInfo], 200, '获取成功', 'json');
        }

    }


    /**
     * 图片上传示例
     */
    public function uploadAvatar()
    {

        QiUpload::qiUpload(\request());

    }

    /**
     * 使用微信扩展示例
     *
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     */
    public function wechat()
    {

        $this->wecaht->base->getValidIps();

        $message = '';

        $this->wecaht->live->getRooms();


    }


}
